import type { FormSchema, DescItem } from 'hickey-ui';

import { useRender } from 'hickey-ui';
import { CONTRACT_TYPES, CONTRACT_STATUS, SIGN_TYPES, CONTRACT_SIGN_STATUS } from './staticData';

const applyforStatus = [
  { label: '未申请', value: 0 },
  { label: '申请中', value: 1 },
  { label: '已申请', value: 2 }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '签约商家',
    field: 'companyName',
    component: 'Input',
    componentProps: {
      placeholder: '请输入签约商家',
      maxLength: 50
    },
    colProps: { span: 6 }
  },
  {
    label: '签约人',
    field: 'companyName',
    component: 'Input',
    componentProps: {
      placeholder: '请输入签约人',
      maxLength: 50
    },
    colProps: { span: 6 }
  },
  {
    label: '签约服务商',
    field: 'taxCompanyName',
    component: 'ApiSelect',
    componentProps: {},
    colProps: { span: 6 }
  },
  {
    label: '申请状态',
    field: 'contractType',
    component: 'Select',
    componentProps: {
      options: applyforStatus
    },
    colProps: { span: 6 }
  },
  {
    label: '创建时间',
    field: 'createTime',
    component: 'RangePicker',
    componentProps: {
      style: { width: '100%' }
    },
    colProps: { span: 6 }
  }
];

export const columns = [
  {
    title: '合同外部编号',
    width: 200,
    dataIndex: 'externalContractNo',
    customRender({ text }) {
      return useRender.renderValue(text);
    }
  },
  {
    title: '合同内部编号',
    width: 240,
    dataIndex: 'contractNo'
  },
  {
    title: '合同类型',
    dataIndex: 'contractType',
    customRender: ({ text }) => CONTRACT_TYPES.find(Item => Item.value === text)?.label || '无'
  },
  {
    title: '签约商家',
    dataIndex: 'companyName'
  },
  {
    title: '合同状态',
    dataIndex: 'contractStatus',
    customRender: ({ text }) => {
      const { label } = CONTRACT_STATUS.find(Item => Item.value === text) as any;
      return useRender.renderTag(label);
    }
  },
  {
    title: '签约状态',
    dataIndex: 'signStatus',
    customRender: ({ text }) => {
      if (!text && text !== 0) return '无';
      const { label } = CONTRACT_SIGN_STATUS.find(Item => Item.value === text) as any;
      return useRender.renderTag(label);
    }
  },
  {
    title: '签约类型',
    dataIndex: 'signType',
    customRender: ({ text }) => SIGN_TYPES.find(Item => Item.value === text)?.label || '无'
  },
  {
    title: '创建时间',
    width: 200,
    dataIndex: 'createTime',
    customRender: ({ text }) => useRender.renderDate(text)
  },
  {
    title: '创建人',
    dataIndex: 'creatorName'
  }
];

export const logSchema: DescItem[] = [
  {
    label: '合同外部编号',
    field: 'externalContractNo',
    span: 2
  },
  {
    label: '合同内部编号',
    field: 'contractNo',
    span: 2
  },
  {
    label: '合同类型',
    field: 'contractType',
    render: value => CONTRACT_TYPES.find(Item => Item.value === value)?.label || '无',
    span: 2
  },
  {
    label: '签约商家',
    field: 'companyName',
    span: 2
  },
  {
    label: '合同状态',
    field: 'contractStatus',
    render: value => CONTRACT_STATUS.find(Item => Item.value === value)?.label,
    span: 2
  },
  {
    label: '签约状态',
    field: 'signStatus',
    render: value => CONTRACT_SIGN_STATUS.find(Item => Item.value === value)?.label || '无',
    span: 2
  },
  {
    label: '签约类型',
    field: 'signType',
    render: value => SIGN_TYPES.find(Item => Item.value === value)?.label || '无',
    span: 2
  },
  {
    label: '创建日期',
    field: 'createTime',
    span: 2,
    render: value => useRender.renderDate(value)
  },
  {
    label: '创建人',
    field: 'creatorName'
  }
];
